<template>
    <div class="activityApply">
        <mu-paper :z-depth="1" class="demo-loadmore-wrap">
            <mu-container ref="container" class="demo-loadmore-content">
                <mu-load-more @load="load" :loading="loading">
                    <div class="note" :style ="note">
                        <div class="inform">
                            <span>活动报名</span>
                        </div>
                        <div class="tabs">
                            <ly-tab  v-model="selectedId" :items="items" :options="options" @change="handleChange"></ly-tab>
                        </div>
                    </div>
                    <div class="list">
                        <div class="bar"  v-for="(item,index) in publishList" :key="index" @click="activityDetails(item)">
                            <!-- status  1活动结束 2已报名 3报名中 -->
                            <div class="bq" :style ="yjs" v-if="item.status==1">
                                <div>
                                    <span>已结束</span>
                                </div>
                            </div>
                            <div class="bq" :style ="notes" v-if="item.status==2">
                                <div>
                                    <span>已报名</span>
                                </div>
                            </div>
                            <div class="bq" :style ="bmz" v-if="item.status==3">
                                <div>
                                    <span>报名中</span>
                                </div>
                            </div>
                            <div class="step1">
                                <div class="title">
                                    <span>{{item.title}}</span>
                                </div>
                            </div>
                            <div class="step2">
                                <span>{{(item.deadline) | time}} 报名截止</span>
                                <span>{{item.party_count}}人参加</span>
                            </div>
                        </div>
                        <!--<div class="loading">{{loaded}}</div>-->
                    </div>
                </mu-load-more>
            </mu-container>
        </mu-paper>
        <div class="loading" v-if="loadOver">{{loaded}}</div>
    </div>
</template>

<script>
    import LyTab from "@cp/index";
    export default {
        components: {
            LyTab
        },
        data() {
            return {
                to: false,
                show: false,
                loading: false,
                org_type: 1,
                loaded: "加載更多...",
                loadOver:false,
                notMore: true,
                p:1,
                publishList:[],
                selectedId: 0,
                bottomSelectedId: 0,
                items: [
                    { label: "所有活动", org_type: "1" },
                    { label: "已报名", org_type: "2" },
                    { label: "未报名", org_type: "3" }
                ],
                options: {
                    activeColor: "#333",
                    color: "#999"
                },

                tab:0,
                note: {
                    backgroundImage: "url(" + require("@as/img/zuzhi_wode_bj@2x.png") + ")",
                    backgroundRepeat: "no-repeat",
                    backgroundSize: "100%",
                },
                notes: {
                    backgroundImage: "url(" + require("@as/img/zuzhi_wode_red@2x.png") + ")",
                    backgroundRepeat: "no-repeat",
                    backgroundSize: "100% ",
                },
                bmz: {
                    backgroundImage: "url(" + require("@as/img/zuzhi_wode_org@2x.png") + ")",
                    backgroundRepeat: "no-repeat",
                    backgroundSize: "100% ",
                },
                yjs: {
                    backgroundImage: "url(" + require("@as/img/zuzhi_wode_hui@2x.png") + ")",
                    backgroundRepeat: "no-repeat",
                    backgroundSize: "100% ",
                },
            }
        },
        mounted() {
            this.$progress.done();
            this.changeTab();
        },
        methods: {
            // 活动详情
            activityDetails (item) {
                this.$router.push({ path: '../organization/activityDetails' , query: item })
            },
            changeTab(p) {
                let that = this;
                // that.publishList=[]
                that.$http
                    .get("/app/Organization/activity_list", {
                        p: that.p,
                        page: 5,
                        type: that.org_type,
                        org_id:JSON.parse(Cookies.get('user_71ydj')).organization_id,
                        uid: JSON.parse(Cookies.get('user_71ydj')).id,
                    })
                    .then(res => {
                        if (res.data.length == 0) {
                            that.loaded = "没有更多";
                            that.notMore = false;
                            return;
                        }
                        // that.publishList=[]
                        console.log(res.data)
                        that.publishList.push(...res.data);
                        this.loadOver =false;
                        if(p!=1){
                            console.log(res.data);
                            if(res.data.length){
                            }else{
                                this.loadOver =true;
                                this.loading =false;
                                this.loaded='没有更多数据了'
                                return false
                            }
                        }else {
                            if(!res.data.length){
                                this.notMore =true;
                            }
                        }
                        // if (res.data.length < 10) {
                        // 	that.loaded = "没有更多了";
                        // 	that.notMore = false;
                        // 	return;
                        // }
                    });
            },
            load() {
                //因为load 触发多次 所以做分时节流
                if (!this.loadOver) {
                    this.loading = true;
                    clearTimeout(this.method);
                    this.method = setTimeout(() => {
                        this.p = this.p + 1;
                        // this.initData(this.p,this.status);
                        this.changeTab(this.p,);
                        this.loading =false;
                    }, 2000);
                }
                // if (this.notMore) {
                // 	clearTimeout(this.method);
                // 	this.method = setTimeout(() => {
                // 		this.p = this.p + 1;
                // 		this.changeTab();
                // 	}, 500);
                // }
            },

            handleChange(item, index) {
                this.p = 1;
                this.org_type = item.org_type;
                this.publishList = [];
                this.loaded = "加载更多...";
                this.notMore = true;
                this.changeTab(this.p);
            }
        },
        created(){

        }
    }
</script>

<style scoped>
    /*.mu-load-more{*/
    /*min-height:100vh;*/
    /*overflow: auto !important;*/
    /*padding: 0 0 15px 0!important;*/
    /*}*/
</style>

<style scoped lang="scss">
    /deep/.ly-tab-active-bar {
        background:-webkit-linear-gradient(left,#eb4e44,#f47447);
        background:-o-linear-gradient(right,#eb4e44,#f47447);
        background:-moz-linear-gradient(right,#eb4e44,#f47447);
        background:linear-gradient(to right,#eb4e44,#f47447);
        border-radius: 10px;
    }

    * {
        margin: 0;
        padding: 0;
    }
    .note{
        padding: 38px 15px 15px 15px;
        box-sizing: border-box;
        width:100%;
        height:234.5px;
        position: relative;
    }
    .inform{
        width:100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 25px;
        span{
            font-size: 28px;
            color:#000;
            font-weight: bold;
        }
    }
    .tabs{
        margin-top: 20px;
        display: flex;
        justify-content: flex-start;
        width:auto;
        margin-left: -15px;
        element.style{
            background-color:red !important;
        }
    }
    .list{
        width:100%;
        padding: 0 15px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        position: absolute;
        left: 0;
        top:200px;
        z-index: 999;
        .bar{
            width:100%;
            box-shadow: 0px 6px 15px 2px #f1f1f1;
            padding: 15px 15px;
            position: relative;
            margin-bottom: 15px;
            background: #fff;
            border-radius: 5px;
            .bq{
                position: absolute;
                right:0;
                top:-6px;
                width:65px;
                height:34.5px;
                div{
                    width:100%;
                    height:22px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    span{
                        color: #fff;
                        font-size: 12px;
                    }
                }
            }
            .step1{
                width:100%;
                display: flex;
                flex-direction: column;
                align-items: center;
                padding: 10px 0;
                box-sizing: border-box;
                .time{
                    width:100%;
                    display: flex;
                    justify-content: flex-start;
                    span{
                        font-size: 12px;
                        color: #999;
                        display: inline-block;
                    }
                }
                .title{
                    width:100%;
                    overflow: hidden;
                    text-overflow:ellipsis;
                    white-space: nowrap;
                    margin: -10px;
                    span{
                        font-size: 14px;
                        color: #333;
                        display: inline-block;
                    }
                }
            }
            .step2{
                width:100%;
                display: flex;
                justify-content: space-between;
                align-items: center;
                span{
                    font-size: 12px;
                    color:#999;
                    margin-left: 3px;
                }
            }
        }
        /*.loading {*/
        /*width: 100%;*/
        /*font-size: 14px;*/
        /*color: #dddddd;*/
        /*display: flex;*/
        /*align-items: center;*/
        /*justify-content: center;*/
        /*margin-top: 24px;*/
        /*}*/
        .loading {
            width: 343px;
            margin: 0 16px ;
            font-size: 14px;
            color: #dddddd;
            clear: both;
            line-height: 61px;
            text-align: center;
        }
    }
</style>
<style scoped lang="scss">
    div  .mu-tabs{
        position: relative;
        z-index: 97;
        height: 40px;
        margin-bottom: 15px;
        background: none!important;
        margin-top: 40px;
    }
    div   .mu-tab-link-highlight {
        width:16px !important;
        height:4px !important;
        background:rgba(244,117,72,1);
        border-radius:2px;
        margin-left: 28px;
    }
    div  .mu-tab{
        font-size:14px;
        font-family:PingFang-SC-Medium;
        font-weight:500;
        color:#333;
    }
    div  .mu-tab-active{
        font-size:18px;
        font-family:PingFang-SC-Medium;
        font-weight:bold;
        color:#333;
    }
    .activityApply{
        height: 100vh;
    }
    .activityApply .demo-loadmore-wrap{
        height: 100%;
    }
    /*.activityApply /deep/ .mu-paper{*/
    /*height: 100%;*/
    /*}*/
    .activityApply /deep/ .container{
        padding: 0;
        /*height: 100%;*/
    }
    .mu-load-more /deep/ .mu-circle-spinner{
        border-color: #e5e5e5;
    }
    .activityApply /deep/ .mu-infinite-scroll{
        display: none;
        height: 0;
    }
    .activityApply /deep/.mu-elevation-1{
        box-shadow: 0 0.05333rem 0.02667rem -0.02667rem rgba(0,0,0,0), 0 0.02667rem 0.02667rem 0 rgba(0,0,0,0), 0 0.02667rem 0.08rem 0 rgba(0,0,0,0); ;
        -webkit-box-shadow:0 0.05333rem 0.02667rem -0.02667rem rgba(0,0,0,0), 0 0.02667rem 0.02667rem 0 rgba(0,0,0,0), 0 0.02667rem 0.08rem 0 rgba(0,0,0,0); ;
    }
</style>
